using UnityEngine;
using System.Collections;

public class pivotRotationScript : MonoBehaviour
{
	public float speed; // exposed it
	public float speedChangeFactor = 0.1f; //exposed
	public bool kickState =false;
	public int score =0;
	public float scoreBarLength;
	public float instructionBarStart;
	public int kickScore ;

	
	// Use this for initialization
	void Start ()
	{
		speed = 0.2f;	
		kickScore = 50;
		transform.RotateAround ((Vector3.up), 180);
		scoreBarLength  = (Screen.width / 4.0f) + 100.0f;
		instructionBarStart = Screen.width * (3.0f/4.0f) - 120.0f;  	
	}
	
	// Update is called once per frame
	

	
	void Update ()
	{
		transform.RotateAround ((Vector3.up), Time.deltaTime * speed);
		
		//Kick state update
		kickState = Input.GetButton ( "Fire1" );
		
		
//		if (Input.GetButtonDown ("Fire1")) 
//			kickState=true;
//		else if ( Input.GetButtonUp ("Fire1") )
//			kickState= false;
	}
	
	
	
	void speedAdjust()
	{
		float tempSpeed = Mathf.Abs (speed);
		tempSpeed += tempSpeed * speedChangeFactor ;
		speed = (speed >0) ? -tempSpeed : tempSpeed ; // in my opinion, its not possible to avoid branching here.

//		bool positive = (speed>=0) ? true : false;
//		speed = (positive)? speed : -speed;
//		speed= speed + speed * speedChangeFactor;
//		if(positive)
//			speed = -speed;
	}
	
	public void OnGUI()
	{
		GUI.Box (new Rect (20.0f, 60.0f, scoreBarLength, 25.0f),  "Score   :   " + score);
		GUI.Box (new Rect (instructionBarStart, 20.0f, scoreBarLength, 25.0f), "HINT   ::     Space for Jump : Left Ctrl for Kick"); 
		GUI.Box (new Rect (instructionBarStart, 60.0f, scoreBarLength, 25.0f), "  Jump to Save from Log  :  Kick the Log to score"); 

	}  
	
	
	void scoreAdjust(int addScore)
	{
		score += addScore;
		print ("Score adjusted");
	}
	
	public void LogCollision(Collider other)
	{		
		// if in kick state, change direction
		if(kickState){
			speedAdjust();
			scoreAdjust (kickScore); 
		}
		// else damage player
		else if (other.tag == "player")
			other.GetComponent<playerBehaviorScript>().damagePlayer();		
	}
}
